<?php

class Dal {
    const SPEC_TABLE = 'specialization';
    const LANG_TABLE = 'language';
    const GROUP_TABLE = 'csoport';
    const USER_TABLE = 'user';
    const INFO_TABLE = 'user_information';

    private static $connected = false;
    private static $host = "localhost"; // Host name
    private static $username = "root"; // Mysql username
    private static $password = ""; // Mysql password
    private static $db_name = "stsdatabase"; // Database name

    public static function connect() {
        mysql_connect(self::$host, self::$username, self::$password) or die("cannot connect");
        mysql_select_db(self::$db_name) or die("cannot select DB");
        mysql_query("SET NAMES 'utf8'");
        self::$connected = true;
    }

    public static function fetchAll($query) {
        if (!self::$connected)
            self::connect();
        $result = mysql_query($query);
        $data = array();
        while ($row = mysql_fetch_assoc($result)) {
            $data[] = $row;
        }
        return $data;
    }

    public static function fetch($query) {
        if (!self::$connected)
            self::connect();
        $result = mysql_query($query);
        $data = array();
        $row = mysql_fetch_assoc($result);
        return $row;
    }

    public static function update($query) {
        if (!self::$connected)
            self::connect();
        $result = mysql_query($query);
        if (mysql_error()) {
            die('Error, query failed:' . mysql_error());
        };
        return $result;
    }

}

?>